Articles

Functions in js

September 04, 2019

what is function

Function is the set or collection of instructions which are kept in the box called function.which when we executes it pefroms a specific task as its output..

Types of Functions In JavaScript

  1. Named Function

    function sum(a,b) {
    return a+b;
    }

    Named function means that function declaration with name eg i have given name to function above is sum

  2. Anonymous Functions

    var sum = function (a,b) {
    return a+b;
    }

    Anonymous Function or function expression means function without name

  3. Immediately invoked function expression (IIFE)

    function (a,b) {
    return a+b;
    })(a,b)

    An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.

  4. Function Execution Or Invocation

    It simply means that the giving command to function for executing the collection of code which we have put inside it

for example: Here im executing the one of function which i have defined above

sum(1,2);

*we can execute the function by its name i have provide arguments inside the brackets at time of execution so the output will be 3.the provided agruments will go inside the parameters which i define above in the function declaration.*

  1. Different Components Of Functions

    Genrelly The Main Components Of The Functions Are

  2. Function Keyword
  3. Function Name
  4. Parameters Of The Function
  5. Return Statement in The Function If Not Provided It Will Going To Return The Undefined
  6. Arguments In The Function at Execution Time